# Maintainer: Jianhua Lu <lujianhua000@gmail.com>
pkgname=firmware-xiaomi-elish
pkgver=20240917
pkgrel=1
pkgdesc="Firmware for Xiaomi Mi Pad 5 Pro"
subpackages="
	$pkgname-adreno
	$pkgname-adsp
	$pkgname-cdsp
	$pkgname-cirrus
	$pkgname-hexagonfs
	$pkgname-initramfs
	$pkgname-slpi
	$pkgname-touchscreen
	$pkgname-venus
	"
url="https://github.com/lujianhua/xiaomi-elish-firmware"
arch="aarch64"
license="proprietary"
options="!check !strip !archcheck !tracedeps pmb:cross-native"
_commit="51e9ac8cd91d88de43fb016530b9421a2713467a"
source="
	https://github.com/lujianhua/xiaomi-elish-firmware/archive/$_commit/xiaomi-elish-firmware-$_commit.tar.gz
	30-dsp-firmware.files
"
builddir="$srcdir/xiaomi-elish-firmware-$_commit"

package() {
	# parent package is empty
	mkdir -p "$pkgdir"
}

# Xiaomi elish boots with secure boot, it can only load signed firmwares.
adreno() {
	pkgdesc="Xiaomi elish adreno firmware"
	depends="firmware-qcom-adreno-a650"

	install -Dm644 "$builddir"/sm8250/a650_zap.mbn -t \
		"$subpkgdir/lib/firmware/qcom/sm8250/xiaomi/elish/"
}

adsp() {
	pkgdesc="Xiaomi elish adsp firmware"

	install -Dm644 "$builddir"/sm8250/adsp* -t \
		"$subpkgdir/lib/firmware/qcom/sm8250/xiaomi/elish/"
}

cdsp() {
	pkgdesc="Xiaomi elish cdsp firmware"

	install -Dm644 "$builddir"/sm8250/cdsp* -t \
		"$subpkgdir/lib/firmware/qcom/sm8250/xiaomi/elish/"
}

cirrus() {
	pkgdesc="Xiaomi elish cirrus firmware"

	install -Dm644 "$builddir"/cirrus/cs35l41* -t \
		"$subpkgdir/lib/firmware/cirrus/"
}

hexagonfs() {
	pkgdesc="Xiaomi elish hexagonfs files"

	mkdir -p "$subpkgdir"/usr/share/qcom/sm8250/xiaomi
	cp -r "$builddir"/hexagonfs/ \
		"$subpkgdir"/usr/share/qcom/sm8250/xiaomi/elish

	# Remove files that we don't need - for now
	rm -r "$subpkgdir"/usr/share/qcom/sm8250/xiaomi/elish/acdb/
	rm -r "$subpkgdir"/usr/share/qcom/sm8250/xiaomi/elish/dsp/
}

initramfs() {
	pkgdesc="Xiaomi elish firmware to be included in the initramfs"

	install -Dm644 "$srcdir/30-dsp-firmware.files" \
		"$subpkgdir/usr/share/mkinitfs/files/30-dsp-firmware.files"
}

slpi() {
	pkgdesc="Xiaomi elish slpi firmware"

	install -Dm644 "$builddir"/sm8250/slpi* -t \
		"$subpkgdir/lib/firmware/qcom/sm8250/xiaomi/elish/"
}

touchscreen() {
	pkgdesc="Xiaomi elish touchscreen firmware"

	install -Dm644 "$builddir"/novatek/nt36523* -t \
		"$subpkgdir/lib/firmware/novatek/"
}

venus() {
	pkgdesc="Xiaomi elish venus firmware"

	install -Dm644 "$builddir"/sm8250/venus.mbn -t \
		"$subpkgdir/lib/firmware/qcom/sm8250/xiaomi/elish/"
}

sha512sums="
c1ebaf280313a00a64c9bc9ebf820574f0bffe26cdf0652a9897068d46e251ae03853e684bf7b26591d557d218c56eb10c36e50358778bcffb36caea948466b5  xiaomi-elish-firmware-51e9ac8cd91d88de43fb016530b9421a2713467a.tar.gz
6faf55b7804e4cc0ceda959b3c19010d0052c18cc1bc1fc4364ddc65ec6d8715175d754b8d4aa837e23a66150b48ebc94c1c16a9ee0b405e824fae1fb6e5ae32  30-dsp-firmware.files
"
